﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using System.Data.SqlClient;
using System.Data;

namespace DAO
{
    public class BIENDOCGIADAO
    {
        public void thembien(LOAIDOCGIADTO ldgDTO)
        {
            SqlConnection conn = DATAPROVIDER.ConnectSQL();
            string sql1 = "INSERT INTO BIEN_DOC_GIA(TenBien,GiaTri) VALUES (@tb,@gt)";
            SqlCommand cmd = new SqlCommand(sql1, conn);

            SqlParameter sqlparameter = new SqlParameter("@tb", System.Data.SqlDbType.NChar, 10);
            sqlparameter.Value = ldgDTO.Maloaidocgia;
            cmd.Parameters.Add(sqlparameter);

            sqlparameter = new SqlParameter("@gt", System.Data.SqlDbType.Int);
            sqlparameter.Value = 0;
            cmd.Parameters.Add(sqlparameter);

            cmd.ExecuteNonQuery();
            conn.Close();
            conn.Dispose();
        }
        public void updatebiendocgia(DOCGIADTO dgDTO)
        {
            SqlConnection conn = DATAPROVIDER.ConnectSQL();
            string sql1 = "SELECT GiaTri FROM BIEN_DOC_GIA WHERE TenBien='" + dgDTO.Maloaidocgia + "'";
            SqlCommand cmd = new SqlCommand(sql1, conn);
            object temp = cmd.ExecuteScalar();
            int temp1 = Convert.ToInt32(temp);
            temp1++;
            string sql = "UPDATE BIEN_DOC_GIA SET GiaTri= " + temp1 + " WHERE TenBien='" + dgDTO.Maloaidocgia + "'";
            cmd = new SqlCommand(sql, conn);
            cmd.ExecuteNonQuery();
            conn.Close();
            conn.Dispose();
        }

    }
}
